package b.cif.api

import akka.NotUsed
import b.utils.formats.JsonFormats
import com.lightbend.lagom.scaladsl.api.{Descriptor, Service, ServiceCall}
import play.api.libs.json.{Format, Json}

/**
  * 贲国称 于 2016/12/12 创建。
  */

object E证件类型 extends Enumeration {
  val e身份证 = Value("I")
  val e军官证 = Value("S")
  private val nameOfValues = Seq[String]("身份证", "军官证")
  def nameOf(v: Value): String = nameOfValues(v.id)
  implicit val format: Format[Value] = JsonFormats.enumFormat(E证件类型)
}

case class CC证件(v证件类型: E证件类型.Value, v证件号: String) {
  override def toString: String = s"$v证件号-$v证件类型"
}
case class CC开客户Request(v证件: CC证件, v户名: String)
case class CC客户(v客户号: String, v证件: CC证件, v户名: String, v状态: String = "N", v账号s: Array[Int] = Array.empty[Int])

object CC开客户Request {
  implicit val format1: Format[CC证件] = Json.format
  implicit val format2: Format[CC开客户Request] = Json.format
}

object CC客户 {
  implicit val format1: Format[CC证件] = Json.format
  implicit val format3: Format[CC客户] = Json.format
}

trait T客户Service extends Service {

  def f开客户(): ServiceCall[CC开客户Request, String]
  def f客户查询(v客户号: String): ServiceCall[NotUsed, CC客户]
  def f取账户序号(v客户号: String): ServiceCall[NotUsed, Int]

  override def descriptor(): Descriptor = {
    import Service._
    named("CIF").withCalls(
      namedCall("/cif/customers", f开客户 _),
      pathCall("/cif/customers/:v客户号/accounts", f取账户序号 _),
      pathCall("/cif/customers/:v客户号", f客户查询 _)
    ).withAutoAcl(true)
  }

}
